package com.jae.security.handle;

import com.jae.model.ResultCode;
import com.jae.model.ResultMsg;
import com.jae.utils.ResponseUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *  客户端认证失败返回结果
 */
@Component
@Slf4j
public class OauthServerAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        log.debug(e.getMessage());
        ResponseUtils.result(httpServletResponse,new ResultMsg(ResultCode.CLIENT_AUTHENTICATION_FAIL.getCode(),false,ResultCode.CLIENT_AUTHENTICATION_FAIL.getMessage()));
    }
}
